package com.learn.io.bio.oneway;

import com.learn.constant.CommonConstant;

import java.io.OutputStream;
import java.net.Socket;

/**
 * 客户端
 */
public class SocketClient {

    static String message = "你好  我给你发一条消息";

    public static void main(String args[]) throws Exception {
        // 要连接的服务端IP地址和端口
        String host = CommonConstant.SOCKET_SERVER_HOST;
        int port = CommonConstant.SOCKET_SERVER_PORT;

        // 与服务端建立连接
        Socket socket = new Socket(host, port);

        // 建立连接后获得输出流
        OutputStream outputStream = socket.getOutputStream();
        socket.getOutputStream().write(message.getBytes(CommonConstant.DEFAULT_CHARSET_NAME));

        outputStream.close();
        socket.close();
    }
}
